Repository navigation
fix: shutdown edge cases from the first review (q during start-up, deploys after Ctrl+C, stale lock) - #6
Conversation
- q stops the run from the deploy on (deploy, download, warm-up), not only in the session. - deploy() checks an abort flag before each region, so cleanup stops a fallback deploy. - A deploy still running when cleanup's wait ends is deleted again once it ends. - The lock is one file linked into place whole, with the owner's pid and command line; only that exact process counts as a running runcoder. - An uncaught error prints ERROR: and the log path on screen, like the normal path. - README names the c and p keys the code uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… q works (setkernel#3) Review nits on setkernel#5: after q the loop kept running during cleanup and could print "The tunnel stopped; reopening it." The README now says q does nothing during the setup and session questions before the deploy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oxes (setkernel#3) The two new tests in 2-recovery used sandboxes t25 and t26, which 4-cost already uses. The test files run in parallel, and sandbox() deletes and recreates tests/tmp/<name>, so when the tests overlap, each wipes the other's fake gcloud state and lock. Run together, both t25 tests fail: one with "runcoder is already running". They now use t29 and t30, which no other test uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node's docs say Windows ends a process about 10 seconds after its console window closes. Closing Qwen Code, then deleting the service and confirming the delete, can take longer than that, so the README tells Windows users to press q or Ctrl+C, or to run runcoder down if they closed the window anyway. Nobody has run this on Windows yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vega-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head 4d41660.
Request changes. The code looks right, and the new tests pass when I run them here. Two things block the merge: the head has no CI checks, and one acceptance criterion of #3 is still not met.
How I checked
- I read
github.json, issue #3, and the whole diffgit diff origin/main...HEAD(4 commits, 9 files). - I ran
pnpm install --frozen-lockfile, then the new tests and the existing lock and shutdown tests on Linux (Node 26), on the fakes:
node --test ... --test-name-pattern="q during|lock left|still running when cleanup|unexpected error|second copy|Ctrl\+C|normal" tests/1-run.test.mjs tests/2-recovery.test.mjs
Result: 8 tests, 8 pass, 0 fail. That covers: a normal run, Ctrl+C during the download, q during the download, q during the deploy, a second copy, a stale lock, a deploy still running after cleanup's wait, and an unexpected error. - I did not run the full
pnpm check(about 5 minutes). The missing CI run blocks the merge either way.
Blockers
-
The head has no checks.
.checksin the workflow's read of the PR is[]for head4d416603..github/workflows/check.ymlruns onpull_requeston ubuntu, macOS and Windows, but no run is attached to this head. The last criterion of #3 also asks for "pnpm checkand CI pass on ubuntu, macos and windows". Please getcheckto run on this head (for example, push the branch from the author's own login, or close and reopen the PR) and let all three systems pass. -
The manual Windows criterion is not met, so the PR cannot close #3. The criterion: "A manual run on Windows: closing the console window during a session deletes the service within the time Windows allows; if it cannot, the README says to press q on Windows. Note who ran it and the result in this issue."
- The PR body says it plainly: "Nobody has run this on Windows yet."
- Neither comment on #3 reports a run. Both only link PRs #5 and #6.
- The README note (
README.md, "Use", step 4) is a good fallback, but the criterion still asks for the run and its note on the issue.
Please change
Closes setkernel/runcoder#3toRefs setkernel/runcoder#3in the PR description, and leave #3 open for the Windows run. Or have someone do the run and note it on #3 before the merge.
Acceptance criteria
| Criterion | Status | Evidence |
|---|---|---|
Abort flag before each region in deploy() |
met | src/cloud.mjs deploy: if (aborted()) return null;; cmdUp passes () => state.cleaning; test "q during the deploy: no next region is tried" passes |
| A late deploy can't leave a service behind | met | src/session.mjs cleanup: if the deploy outlives the wait, it deletes, waits for the deploy with no cap, then deletes again; test "a deploy still running when cleanup's wait ends…" passes |
| q during the deploy, download or warm-up; a test shows it | met | src/ui.mjs quitOnQ and push; tests "q during the download…" and "q during the deploy…" pass |
| Stale-lock check accepts only a runcoder process | met | src/session.mjs lock() compares the full recorded command line; test "a lock left by a process ID another program now has is taken over" passes |
| Manual Windows run, noted on the issue | not met | Blocker 2 |
| README "Use" names c / p | met | README.md: "(c), pick one (p), or start fresh (Enter)" |
| Lock written in one step | met | acquireLock writes a temp file, then linkSync puts it in place |
Unexpected error prints ERROR: and Full log: |
met | bin/runcoder.mjs handler; test "an unexpected error is shown…" passes |
A test for each change; pnpm check and CI on three systems |
tests met; CI not met | Blocker 1 |
Scope and tests
- Scope: every source file is named in #3's "Files likely touched". The one exception is
bin/runcoder.mjs, which a criterion of #3 names itself.tests/fake/*are test fakes. - Edits to existing tests: in
tests/1-run.test.mjsandtests/2-recovery.test.mjs, only the header comments and imports change. Intests/fake/gcloud.mjs, the deploy delay is now configurable and still defaults to 1 s. No assertion is dropped, skipped or loosened, and no expected value changes. - No secrets in the diff. Risk class is normal.
Nits (not blocking)
src/session.mjslock(): ifcommandOf(other.pid)fails for a moment and returns"", it no longer equals the recorded command. A live runcoder's lock is then taken over, and two runs can start. On WindowscommandOfgoes through PowerShell, so this is more likely there. Treating an empty result as "still running" would be safer.src/session.mjslock(): two starts that both find a stale lock can still both win (A removes it and links its own; B, which read the stale contents earlier, removes A's lock). This race existed before withmkdirtoo, and #3 does not ask for it. It could be a follow-up.src/ui.mjsquitOnQ: an earlier q that triggers the quit stays inqueue. This is harmless today, becausefinishonly runs once.src/session.mjscleanup: the second wait (await deploying) has no cap, which #3 allows. If gcloud hangs, the window just shows "deleting again as soon as it ends…". A line telling the user they can runruncoder downfrom another window would help.
rigel-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head 4d41660.
What I checked
- Read
github.json(no checks, no earlier reviews), issue #3 and its acceptance criteria, and the whole diffgit diff origin/main...HEAD. It has 4 commits and 9 files. - Read the code around the change:
bin/runcoder.mjs(finish, handlers),src/session.mjs(lock,cleanup,session,cmdUp),src/ui.mjs(keyboard queue),src/proc.mjs(alive,commandOf,sleep),src/tunnel.mjs(waitForTunnel,waitForModel,warmModel) andsrc/config.mjs(timeScale,paths.lock). - Ran the new tests and the ones they sit beside, on Linux, after
pnpm install --frozen-lockfile:
node --test --test-concurrency=4 --test-force-exit --test-name-pattern="q during|lock left by|still running when cleanup|unexpected error|second copy|Ctrl\+C|normal" tests/1-run.test.mjs tests/2-recovery.test.mjsgave 8 tests, 8 pass, 0 fail. I did not run the fullpnpm check. - Edits to existing tests: in
tests/1-run.test.mjsandtests/2-recovery.test.mjsonly the header comment and the imports changed, plus new tests. Intests/fake/gcloud.mjs, the deploy still takes 1 s by default, and only the newdeploy_secondsfile changes that. No assertion was dropped, skipped or loosened, and no expected value changed. - Scope:
bin/runcoder.mjsis not in "Files likely touched", but the issue's criterion names its handler, so it is in scope. The other new files are test fakes. No secrets in the diff.
Blockers
1. The head has no checks
github.json .checks is [] for head 4d41660. .github/workflows/check.yml should run pnpm check on ubuntu, macOS and Windows for every pull_request, but no run is recorded for this head. The issue's last criterion asks for "pnpm check and CI pass on ubuntu, macos and windows", and the PR body says CI was "Not run here". Get the check workflow to run on this head (for example by re-running it or pushing again) and pass on all three systems. Windows matters most here: the new lock code calls commandOf(process.pid), which uses PowerShell Get-CimInstance on Windows, and it hard-links the lock with linkSync. Only CI tests those on Windows.
2. Not every acceptance criterion is met, so Closes must become Refs
These criteria are still open:
- "A manual run on Windows ... Note who ran it and the result in this issue." Nobody has run it. The PR body says so, and issue #3 has no note of a run. The README fallback (
README.md, "On Windows, press q or Ctrl+C rather than closing the window") is the right interim text. But the criterion also asks for the run and a note of its result. - "
pnpm checkand CI pass on ubuntu, macos and windows". See blocker 1.
Please change Closes setkernel/runcoder#3 to Refs setkernel/runcoder#3 in the PR description, so the issue stays open for the Windows run. That is a body-only fix. Fixing blocker 1 needs a check run on the head.
Criteria I could confirm
- Abort flag before each region:
src/cloud.mjsdeploy()checksaborted()at the top of each loop, andcmdUppasses() => state.cleaning. Test "q during the deploy: no next region is tried" passed. - A late deploy can't leave a service behind:
cleanupdeletes, thenawait deploying, then deletes again (src/session.mjs, thelatebranch). Test "a deploy still running when cleanup's wait ends ..." passed. - q during deploy, download or warm-up:
quitOnQinsrc/ui.mjstakes q at once, andcmdUpinstalls it before the deploy. A q already in the queue counts too. Tests "q during the download" and "q during the deploy" passed. - Exact owner check for the stale lock: the lock records
{pid, command}, andlock()compares the full command line. Test "a lock left by a process ID another program now has is taken over" passed. A lock directory left by the old version reads asEISDIR. It is treated as stale and removed, and the run continues. - Lock written in one step: the contents go to a temp file first, then
linkSyncputs it in place. - Unexpected error on screen: the handler in
bin/runcoder.mjsprintsERROR:andFull log:unless cleanup has started. Test "an unexpected error is shown with the log path" passed. - README "Use" names c, p and Enter, and says r reopens Qwen Code during the session.
Nits (non-blocking)
- q during the download can still reopen the tunnel.
cleanupcloses the tunnel, butwaitForModel(src/tunnel.mjs:111-114) andwaitForTunnel(src/tunnel.mjs:81) calltunnel.start()when it is not alive. If the model becomes ready while the delete runs, start-up can go on towarmModelandopenQwenafterstopQwenhas run, and leave a Qwen Code window open. Nothing bills, because the service is deleted and the finalstate.tunnel?.close()runs beforeprocess.exit. The comment inbin/runcoder.mjsassumes start-up will "fail on the closed tunnel". Astate.cleaningcheck in those loops, or beforeopenQwen, would close this gap. I reasoned this from the code and did not reproduce it. - Every start now spawns PowerShell on Windows (
commandOf(process.pid)inlock()) just to record its own command line. On Windows that can add about a second to start-up. It is harmless, but worth knowing. - Upgrading during a session: a runcoder from before this PR holds a lock directory. The new code reads it as stale (
EISDIR) and removes it without checking whether that process is alive. So a run started with the new version while an old-version session is live would take over its lock. This is rare. RUNCODER_TIME_SCALEnow also shortens cleanup's wait for the deploy (sleep(600 * s.timeScale)). That is fine for tests, and the second delete covers a user who sets it.
…edge-cases-from-the # Conflicts: # README.md
…s as running (setkernel#3) Review nit on setkernel#6: commandOf returns "" when ps or PowerShell fails for a moment; that no longer lets a second run take a live runcoder's lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Changes round for @vega-setkernel's review of Blocker 1: the head had no CI checks. This run can't start CI itself. It pushes two new commits (below), and that push starts Blocker 2: the manual Windows criterion isn't met. I agree. This run changes Conflict with Nit 1 (taken): an empty Nits 2–4 (not taken): they fall outside this round. Nit 2 (two starts racing over a stale lock) was already possible before this PR and would make a good follow-up issue. Nits 3 and 4 are harmless today. The description is out of date in two places:
The run set the keyword for #3 to Refs in the PR's description (1 line(s)). Board-sync asks the reviewers again after the push. |
vega-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head 9ce2a87.
Approve. Both blockers from my review of 4d41660 are fixed. CI ran on this head and passed on all three systems. The PR now says Refs setkernel/runcoder#3. The new code (the lock-owner fix) is correct.
How I checked
- I read
github.json, issue #3, the author's changes-round comment, and the whole diffgit diff origin/main...HEAD. After the merge oforigin/main(d450111), only 2 files differ frommain:README.md(+4/−2) andsrc/session.mjs(+3/−2). The rest of this branch is already onmainthrough #5. - Checks on head
9ce2a87:check (ubuntu-latest),check (macos-latest)andcheck (windows-latest)are allcompleted/success. - I read
lock()andacquireLock()insrc/session.mjs:20-49andcommandOf()insrc/proc.mjs:59-69.commandOfreturns""on any error. - I ran
pnpm install --frozen-lockfile, thennode --test --test-force-exit --test-name-pattern="lock left|second copy|stale|lock" tests/2-recovery.test.mjson Linux (Node 26.13.1). Result: 2 tests, 2 pass, 0 fail ("a second copy is refused and leaves the first alone"; "a lock left by a process ID another program now has is taken over"). I did not run the fullpnpm checkhere, because CI ran it on all three systems.
Earlier blockers
- No checks on the head. Fixed: the three
checkjobs passed on9ce2a87. - The manual Windows criterion is not met, so the PR could not close #3. Fixed: the description now says
Refs setkernel/runcoder#3, so #3 stays open for the Windows run.
The new code
src/session.mjs lock():
const now = other.pid && alive(other.pid) ? await commandOf(other.pid) : null;
if (now !== null && (!other.command || !now || now === other.command)) die(...)- The ternary binds after
&&, sonowisnullwhen there is no pid or the process is dead. That lock is taken over, as before. - Process alive, and its command line can't be read (
""): the lock counts as running. This fixes my earlier nit 1. - Process alive, and its command line is readable but different: the lock is taken over (this test passes).
- Process alive with the same command line, or the lock recorded no command: the lock counts as running ("second copy" test passes).
Acceptance criteria of #3 (for this PR's remaining diff)
- Windows criterion, README fallback half: met.
README.md"Use" step 4 now says "On Windows, press q or Ctrl+C rather than closing the window… If you closed it anyway, runruncoder down". "Safety" points to that note. The manual run and its note on #3 are still open, whichRefsallows. - Stale-lock check: still met, and now safer when
commandOffails for a moment. - CI on ubuntu, macOS and Windows: met on this head.
- The other criteria were met by the code that #5 merged. I checked them in my earlier review of
4d41660, and this merge changed none of that code.
Scope, tests, secrets
- Both changed files are named in #3's "Files likely touched".
- The diff against
mainchanges no test files, so there is nothing for the test-diff guard. - No secrets in the diff. Risk class is normal.
Nits (not blocking)
- The new "alive, but the command line can't be read" branch has no test. Making
ps/ PowerShell fail inside a fake is awkward, so a code comment (already there) may be enough. - A small race: if the lock's process exits between
alive()andps, thenps -pfails,commandOfreturns"", and this start refuses with "already running". The next start takes the lock over, so this only costs a retry. Note thatruncoder downdoes not clear the lock (cleanupremoves it only whenstate.locked,src/session.mjs:93), so the "or run: runcoder down" hint does not help in that case. - As the author's comment says, the PR description's "What changed" and "Tests" sections still describe work that is already on
mainthrough #5. Before the merge, it would help to trim them to the README note and thelock()fix, so the squash commit message is accurate.
rigel-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head 9ce2a87.
Approve. I found no merge blockers. After the merge of main, this head changes two files: a Windows note in README.md, and the lock owner check in src/session.mjs lock(). All three CI checks pass, and the lock tests pass when I run them here.
How I checked
- I read
github.json, issue #3, vega-setkernel's earlier review of4d41660, the author's reply, and the whole diffgit diff origin/main...HEAD: 2 files, +7 −4. - Checks:
check (ubuntu-latest),check (macos-latest)andcheck (windows-latest)all show completed / success on head9ce2a87. This clears blocker 1 of the earlier review. - Keyword: the PR body now ends with
Refs setkernel/runcoder#3, so #3 stays open for the manual Windows run. This clears blocker 2 of the earlier review. - Lock change (
src/session.mjs:43-44):nowisnullwhen the lock has no pid or its process is dead. Otherwise it holds the live process's command line, which can be"". The lock counts as live whennow !== nulland one of these holds: the lock recorded no command, the command can't be read now (!now), or the command matches. Compared withmain, the only new case is that a live pid whose command line can't be read now counts as running. Because of the operator precedence of?:and&&, an empty or corrupt lock file (other = {}) still givesnow = null, so it is taken over.commandOf(src/proc.mjs:59-69) returns""on any error. - Tests I ran on Linux (Node 26.13.1), after
pnpm install --frozen-lockfile:node --test --test-force-exit --test-timeout=300000 --test-name-pattern="lock left|second copy" tests/2-recovery.test.mjs. Result: 2 tests, 2 pass, 0 fail ("a second copy is refused and leaves the first alone"; "a lock left by a process ID another program now has is taken over"). I did not run the fullpnpm check, because CI ran it green on all three systems. - README: the new note under "Use" and the pointer under "Safety" match the code. Node's docs do say Windows ends the process about 10 seconds after its console closes.
- Scope and org rules: both files are named in #3's "Files likely touched". No test file is changed, and I found no secrets.
Acceptance criteria of #3
PR #5 (2e61396) already merged most of #3. This PR adds the README fallback for the Windows criterion and tightens the lock check. The PR uses Refs, so not every criterion needs to be met here.
- The stale-lock criterion is still met: a readable command line that differs from the recorded one is taken over. The test "a lock left by a process ID another program now has…" passes.
- The README half of the Windows criterion is met (
README.md, "Use", step 4). The manual Windows run and its note on #3 are still open. That is correct for aRefsPR. pnpm checkand CI pass on ubuntu, macOS and Windows (see the checks above).
Nits (non-blocking)
- On Windows, a user without admin rights often can't read the
CommandLineof an elevated or other-user process throughGet-CimInstance, which then returns empty. If a stale lock's pid is reused by such a process, every start now stops with "runcoder is already running … or run: runcoder down". Butruncoder downdoes not remove the lock:cmdDown(src/session.mjs:310) never takes the lock, andcleanupremoves it only whenstate.locked. The user would have to delete the lock file by hand. This is rare and errs on the safe side, but a follow-up could havedownclear a lock whose owner is dead or unreadable, or have the message name the lock file. - The new branch (live owner, command line unreadable now) has no test. It is hard to fake, so this is only a note.
- As the author's comment says, the "What changed" and "How it was tested" sections of the PR description still describe work that #5 merged. Updating them would help whoever reads the merged PR.
Summary
Fixes the shutdown edge cases from the first review of #1. A GPU can no longer start for nothing or stay running after q, Ctrl+C or an error during start-up. The lock can no longer be mistaken for someone else's. The README now matches the keys the code uses.
This run (on top of the earlier commits in this PR) adds one README note. On Windows, closing the console window may not leave enough time to delete the server, so Windows users should press q or Ctrl+C instead. Nobody has run this on Windows yet. That criterion still needs a person on a Windows machine (see below).
What changed
src/ui.mjsquitOnQ,src/session.mjscmdUp): q stops the run and deletes everything during the deploy, the model download and the warm-up, not only during the session. A q typed earlier and not yet read counts too. After q, the session loop stops, so it can no longer try to reopen the tunnel that cleanup closed.src/cloud.mjsdeploy):deploy()checks an abort flag (state.cleaning) before each region and returnsnullonce it is set.src/session.mjscleanup): if the deploy is still running when the 600 s wait ends, cleanup deletes, waits for the deploy to end (no cap), and deletes again.src/session.mjsacquireLock/lock): the lock is a file holding{pid, command}. It is written to a temporary file and hard-linked into place, so another run never sees a half-written lock. A lock counts as live only if its process is alive and has the same command line it recorded. Any other command line that merely contains "runcoder" no longer counts.bin/runcoder.mjs): theuncaughtException/unhandledRejectionhandler printsERROR:andFull log:like the normal error path. During cleanup it only logs.runcoder downif they closed it anyway. Node's docs say Windows ends a process about 10 seconds after its console closes. Closing Qwen Code (PowerShell), then a gcloud delete and its confirmation, can take longer than that. "Safety" points to that note.Tests
New tests on the fakes:
tests/1-run.test.mjs: "q during the download deletes everything"; "q during the deploy: no next region is tried, everything is deleted".tests/2-recovery.test.mjs: "a lock left by a process ID another program now has is taken over"; "a deploy still running when cleanup's wait ends is deleted once it ends"; "an unexpected error is shown with the log path, and everything is deleted" (withtests/fake/unexpected-error.mjs).Each one checks that the fake service was deleted (
noService).How it was tested
pnpm checkon Linux (this run): passed:node --checkon every module, then 43 tests, 43 pass, 0 fail (exit 0). It ran on the tree before the README-only commit; no test reads the README.Not done: manual Windows run
One acceptance criterion asks for a manual run on Windows: close the console window during a session and see whether the service is deleted in time. This run is on Linux, and I could not do it here. The README now gives the fallback the issue allows ("press q on Windows"). That note is safe whichever way the test turns out. Someone with a Windows machine and a Google Cloud project should run it and note who ran it and the result in #3. If the delete does finish in time, the note can be dropped.
🤖 Generated with Claude Code
Refs #3